import { createStore } from "vuex";

import vuexPer from "vuex-persistedstate";
//也是一个持久化工具
export default createStore({
  state: {
    history: [],
  },
  mutations: {
    setHistory(state, val) {
      state.history.forEach((item, index) => {
        if (item == val) {
          state.history.splice(index, 1);
        }
      });
      //判重

      state.history.splice(4, 1);
      state.history.unshift(val);
      //最多添加五条 往开头添加
    },

    remove(state, index) {
      state.history.splice(index, 1);
    },

    clear(state) {
      state.history = [];
    },
  },
  actions: {},
  modules: {},
  plugins: [vuexPer()],
});
